package com.aloha.springframework.aop.framework;

import com.aloha.springframework.aop.AdvisedSupport;
import com.aloha.springframework.aop.TargetSource;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;

import java.util.List;

/**
 * @author DaiZhiHeng
 * @description 使用CGLIB进行代理
 * @date 2023/7/7 10:07
 */
public final class CglibAopProxy extends AbstractDynamicAopProxy implements AopProxy {


    public CglibAopProxy(AdvisedSupport advised) {
        super(advised);
    }

    @Override
    public Object getProxy() {
        Enhancer enhancer = new Enhancer();
        TargetSource targetSource = advised.getTargetSource();
        enhancer.setInterfaces(targetSource.getTargetClass());
        enhancer.setSuperclass(targetSource.getTarget().getClass());
        enhancer.setCallback(this);
        return enhancer.create();
    }

}
